package com.timepies.domain;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.timepies.R;
import com.timepies.util.Intervallo;

public class TimepieAdapter extends ArrayAdapter<Timepie> {

	public TimepieAdapter(Context context, int layout, List<Timepie> list) {
		super(context, layout, list);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		int color = Pie.randomColor(position);

		View view = LayoutInflater.from(getContext()).inflate(
				R.layout.activity_pie_elenco_riga, null);

		TextView txtTesto = (TextView) view.findViewById(R.id.txt_testo);
		TextView txtOggetto = (TextView) view.findViewById(R.id.txt_oggetto);
		TextView txtDate = (TextView) view.findViewById(R.id.txt_date);
		txtTesto.setText(getItem(position).getTesto());
		txtOggetto.setText(getItem(position).getOggetto());
		txtDate.setText(getItem(position).getData());
		LinearLayout l = (LinearLayout) view.findViewById(R.id.color);
		l.setBackgroundColor(color);
		TextView amg = (TextView) view.findViewById(R.id.anno_mese_giorno);
		amg.setText(Intervallo.printTxtElapsed(getItem(position).getData(),
				false));

		return view;
	}

}